<?php

namespace backend\models;

use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\models\EsProduct;

/**
 * EsProductSearch represents the model behind the search form of `app\models\EsProduct`.
 */
class EsProductSearch extends EsProduct
{
    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['id', 'name', 'spu', 'template_id', 'template_no', 'product_type', 'is_customize', 'magento_template_id', 'brand', 'osku', 'main_sku', 'oid', 'gender', 'is_clearance', 'support_stock', 'short_description', 'description', 'copyright', 'uid', 'created_at', 'updated_at', 'fids', 'plating_color', 'style', 'occasion', 'recipient', 'gtin', 'img_change', 'fids_pic', 'fids_zip', 'status', 'review_num', 'product_set_number', 'qty_ordered'], 'safe'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = EsProduct::find();

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query->andFilterWhere(['like', 'id', $this->id])
            ->andFilterWhere(['like', 'name', $this->name])
            ->andFilterWhere(['like', 'spu', $this->spu])
            ->andFilterWhere(['like', 'template_id', $this->template_id])
            ->andFilterWhere(['like', 'template_no', $this->template_no])
            ->andFilterWhere(['like', 'product_type', $this->product_type])
            ->andFilterWhere(['like', 'is_customize', $this->is_customize])
            ->andFilterWhere(['like', 'magento_template_id', $this->magento_template_id])
            ->andFilterWhere(['like', 'brand', $this->brand])
            ->andFilterWhere(['like', 'osku', $this->osku])
            ->andFilterWhere(['like', 'main_sku', $this->main_sku])
            ->andFilterWhere(['like', 'oid', $this->oid])
            ->andFilterWhere(['like', 'gender', $this->gender])
            ->andFilterWhere(['like', 'is_clearance', $this->is_clearance])
            ->andFilterWhere(['like', 'support_stock', $this->support_stock])
            ->andFilterWhere(['like', 'short_description', $this->short_description])
            ->andFilterWhere(['like', 'description', $this->description])
            ->andFilterWhere(['like', 'copyright', $this->copyright])
            ->andFilterWhere(['like', 'uid', $this->uid])
            ->andFilterWhere(['like', 'created_at', $this->created_at])
            ->andFilterWhere(['like', 'updated_at', $this->updated_at])
            ->andFilterWhere(['like', 'fids', $this->fids])
            ->andFilterWhere(['like', 'plating_color', $this->plating_color])
            ->andFilterWhere(['like', 'style', $this->style])
            ->andFilterWhere(['like', 'occasion', $this->occasion])
            ->andFilterWhere(['like', 'recipient', $this->recipient])
            ->andFilterWhere(['like', 'gtin', $this->gtin])
            ->andFilterWhere(['like', 'img_change', $this->img_change])
            ->andFilterWhere(['like', 'fids_pic', $this->fids_pic])
            ->andFilterWhere(['like', 'fids_zip', $this->fids_zip])
            ->andFilterWhere(['like', 'status', $this->status])
            ->andFilterWhere(['like', 'review_num', $this->review_num])
            ->andFilterWhere(['like', 'product_set_number', $this->product_set_number])
            ->andFilterWhere(['like', 'qty_ordered', $this->qty_ordered]);

        return $dataProvider;
    }
}
